package gui;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class ImageSetup extends JDialog{
	
	public static final int CONFIRM = 0;
	
	public static final int CANCEL = 1;

	private JTextField mTxtWidth;
	
	private JTextField mTxtHeight;
	
	private JButton btnConfirm;
	
	private JButton btnCancel;
	
	private JPanel pnlForm;
	
	private int mReturn = CANCEL;
	
	public ImageSetup() {
		init();
		setModal(true);
	}
	
	private void init() {
	
		setLayout(new BorderLayout());
		
		GridBagLayout layout = new GridBagLayout();
		GridBagConstraints c = new GridBagConstraints();
		pnlForm = new JPanel();
		pnlForm.setLayout(layout);
		
		c.anchor = GridBagConstraints.EAST;
		
		c.gridx = 0;
		c.gridy = 0;
		pnlForm.add(new JLabel("Largura:"));
		
		mTxtWidth = new JTextField(4);
		c.gridx = 1;
		c.gridy = 0;
		pnlForm.add(mTxtWidth, c);
		
		c.gridx = 2;
		c.gridy = 0;
		pnlForm.add(new JLabel("px"), c);
		
		c.gridx = 0;
		c.gridy = 1;
		pnlForm.add(new JLabel("Altura:"), c);
		
		mTxtHeight = new JTextField(4);
		c.gridx = 1;
		c.gridy = 1;
		pnlForm.add(mTxtHeight, c);
		
		c.gridx = 2;
		c.gridy = 1;
		pnlForm.add(new JLabel("px"), c);
		
		add(pnlForm, BorderLayout.CENTER);
		
		JPanel pnlButtons = new JPanel();
		
		btnConfirm = new JButton("Criar");
		btnConfirm.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				mReturn = CONFIRM;	
				setVisible(false);
			}
		});
		
		btnCancel = new JButton("Cancelar");
		btnCancel.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				mReturn = CANCEL;	
				setVisible(false);
			}
		});
		
		pnlButtons.add(btnConfirm);
		pnlButtons.add(btnCancel); 
		
		add(pnlButtons, BorderLayout.SOUTH);
		
	}
	
	public double getSelectedWidth() {
		return Double.parseDouble(mTxtWidth.getText());
	}
	
	public double getSelectedHeight() {
		return Double.parseDouble(mTxtHeight.getText());
	}
	
	public int getReturn() {
		return mReturn;
	}
	
	public static void main(String args[]){
		
		ImageSetup setup = new ImageSetup();
		
		setup.setSize(400,400);
		setup.setVisible(true);
		
		System.out.print(setup.getReturn());
	}
	
}
